<template>
	<jk-dialog
		v-model="showDialog"
		title="详情-生产投料合计"
		width="600px"
		:show-content-loading="showLoading"
		append-to-body
		:show-close-btn="true"
		:show-confirm-btn="false"
		:show-cancel-btn="false"
		@on-close="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
	>
		<el-form ref="ruleForm" :model="ruleForm" label-width="80px" :show-message="false">
			<el-row ref="box1">
				<div>
					<div>
						<!--						<el-col :span="12">-->
						<!--							<el-form-item class="margin-bottom-10" label="单据编号">-->
						<!--								<span class="read-only-2">{{ ruleForm.code || '系统自动生成' }}</span>-->
						<!--							</el-form-item>-->
						<!--						</el-col>-->
						<!--						<el-col :span="12">-->
						<!--							<el-form-item class="margin-bottom-10" label="投料序号">-->
						<!--								<span class="read-only-2">{{ ruleForm.sortNum || '系统自动生成(同班次依次递增)' }}</span>-->
						<!--							</el-form-item>-->
						<!--						</el-col>-->
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="投料日期">
								<jk-date-picker v-model="ruleForm.belongDate" disabled size="medium" placeholder="投料时间" />
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="投料班次">
								<span class="read-only-2">{{ ruleForm.shiftName }}</span>
							</el-form-item>
						</el-col>
						<el-col
							v-for="(item, index) in ruleForm.empList"
							:key="item.id || index"
							:span="24"
						>
							<div class="flex-start">
								<el-form-item class="margin-bottom-10" label-width="100px" label="投料人" style="width: 50%;">
									<span class="read-only-2">{{ item.name }}</span>
								</el-form-item>
								<el-form-item class="margin-bottom-10" label-width="100px" label="投料占比" style="width: 50%;">
									<span class="read-only-2">{{ item.feedstockPercentage }}</span>
								</el-form-item>
							</div>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="清花线">
								<span class="read-only-2">{{ ruleForm.productionLineName }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="品种">
								<span class="read-only-2">{{ ruleForm.productName }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="批号">
								<span class="read-only-2">{{ ruleForm.batchCode }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="仓数">
								<span class="read-only-2">{{ ruleForm.warehouseNumber }}</span>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="总重">
								<jk-input v-model="ruleForm.allQty" disabled></jk-input>
							</el-form-item>
						</el-col>
						<el-col :span="24">
							<el-form-item class="margin-bottom-10" label-width="100px" label="每仓重量(吨)">
								<span class="read-only-2">{{ ruleForm.warehouseQty }}</span>
							</el-form-item>
						</el-col>
					</div>
				</div>
			</el-row>
		</el-form>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import { productionFeedstockTotalGet } from '../../../../api/production/feedingMaterialTotal';
    export default {
        name: 'FeedingMaterial',
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            dataId: {
                type: [String, Number],
                default: ''
            }
        },
        mixins: [calHeight],
        data() {
            return {
                lapWasteVarietyList: [],
                showDialog: false,
                showLoading: true,
                throwMaterialList: '',
                ruleForm: {
                    'empList': [],
                    'productList': []
                }
            };
        },
        methods: {
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    Object.assign(this.$data, this.$options.data());
                    this.$nextTick(() => {
                        this.$refs.ruleForm.resetFields();
                    });
                }
            },
            getDetailRequest() {
                this.showLoading = true;
                productionFeedstockTotalGet({ id: this.dataId }).then(res => {
                    this.showLoading = false;
                    if (res.data.status === 200) {
                        this.ruleForm = res.data.res;
                        const arry = [];
                        this.ruleForm.empList.forEach(x => {
                            arry.push(x.name);
                        });
                        this.throwMaterialList = arry.join('、'); // 使用空格作为分隔符
                    }
                });
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.getDetailRequest();
                }
            }
        }
    };
</script>
<style scoped>
.box {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tabLeft {
  margin-right: 10px;
}
</style>
